import 'package:flutter/material.dart';
import 'package:get/get.dart';

class MainTabLogic extends GetxController with GetTickerProviderStateMixin {
  final _currentIndex = 0.obs;
  int get currentIndex => _currentIndex.value;
  late var tabController = TabController(length: 3, vsync: this);

  @override
  void onInit() {
    super.onInit();
    tabController.addListener(() {
      _currentIndex.value = tabController.index;
    });
  }

  void reattachTabController() {
    tabController.dispose();
    tabController = TabController(length: 3, vsync: this);
    tabController.addListener(() {
      _currentIndex.value = tabController.index;
    });
    _currentIndex.value = 0;
  }

  void changeTabIndex(int index) {
    tabController.animateTo(index);
  }

  @override
  void dispose() {
    tabController.dispose();
    super.dispose();
  }
}
